package cn.zwx.learn.mybatis.example;

import cn.zwx.learn.mybatis.example.demo.entity.UserEntity;
import cn.zwx.learn.mybatis.example.demo.mapper.UserMapper;
import cn.zwx.learn.mybatis.example.croe.session.Configuration;
import cn.zwx.learn.mybatis.example.croe.session.DefaultSqlSession;
import cn.zwx.learn.mybatis.example.croe.session.SqlSessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @author zhangwenxue
 */
@SpringBootApplication
public class LearnMybatisExampleApplication {

    private static final Logger logger = LoggerFactory.getLogger(LearnMybatisExampleApplication.class);


    public static void main(String[] args) {
        // 构建SqlSessionFactory
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactory().build();
        // 构建DefaultSqlSession
        DefaultSqlSession defaultSqlSession = sqlSessionFactory.openSqlSession();
        UserMapper mapper = defaultSqlSession.getMapper(UserMapper.class);
        UserEntity userEntity = mapper.selectByPrimaryId(1L);
        UserEntity userEntity3 = mapper.selectByPrimaryId2(2L);
        logger.info("执行成功 userEntity:{}",userEntity);
        logger.info("执行成功 userEntity3:{}",userEntity3);
        // 模拟触发二级缓存 二级缓存是Mapper级别的
        // 构建SqlSessionFactory
        SqlSessionFactory sqlSessionFactory2 = new SqlSessionFactory().build();
        DefaultSqlSession defaultSqlSession2 = sqlSessionFactory2.openSqlSession();
        UserMapper mapper2 = defaultSqlSession2.getMapper(UserMapper.class);
        UserEntity userEntity2 = mapper2.selectByPrimaryId(1L);
        logger.info("执行成功 userEntity2:{}",userEntity2);

    }

}
